/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package p2p.raca.Client;

import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 *
 * @author p
 */
public class checkOnlineHost extends Thread {
    
    
    
    @Override
    public void run(){
        

        int i;
        while(true){
        Lista.LoadLista();
        String name1; 
        boolean reachable=false; 
            try {
                //Lista.PrintNomes();
                //String ipAddress;
                for(i=0; i < Lista.Listanomes.size() ; i++){
                    name1 = Lista.getElem(i);
                    try
                    {
                        InetAddress address = InetAddress.getByName(name1);
                    
                    reachable =address.isReachable(3000); 
                    if (!reachable){
                        Lista.removeElem(Lista.getElem(i));
                        i--;
                    }
                    }
                    catch (UnknownHostException e){
                         Lista.removeElem(Lista.getElem(i));
                         i--;
                    } catch (IOException e){
                        Lista.removeElem(Lista.getElem(i));
                        i--;
                }
                }
                Lista.PrintNomes();
                Thread.sleep(30000);
            
            }catch (InterruptedException ex) {
            }
           
                
        }
        
    }
    
}
